home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dde2 / ddeserve.frm < prev    next >
Text File  |  1993-05-16  |  8KB  |  276 lines

  1. VERSION 2.00
  2. Begin Form DDESERVER 
  3.    Caption         =   "DDE Server"
  4.    ClientHeight    =   3660
  5.    ClientLeft      =   1815
  6.    ClientTop       =   1680
  7.    ClientWidth     =   4770
  8.    Height          =   4350
  9.    Icon            =   DDESERVE.FRX:0000
  10.    Left            =   1755
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "DdeServe"
  13.    ScaleHeight     =   3660
  14.    ScaleWidth      =   4770
  15.    Top             =   1050
  16.    Width           =   4890
  17.    Begin TextBox Text2 
  18.       Height          =   2175
  19.       Left            =   1320
  20.       MultiLine       =   -1  'True
  21.       TabIndex        =   2
  22.       Top             =   960
  23.       Width           =   3015
  24.    End
  25.    Begin TextBox Text1 
  26.       Height          =   375
  27.       Left            =   1320
  28.       TabIndex        =   0
  29.       Top             =   360
  30.       Width           =   3015
  31.    End
  32.    Begin Label lblStatus 
  33.       Height          =   255
  34.       Left            =   0
  35.       TabIndex        =   4
  36.       Top             =   3360
  37.       Width           =   4695
  38.    End
  39.    Begin Label Label2 
  40.       BackStyle       =   0  'Transparent
  41.       Caption         =   "Text 2:"
  42.       Height          =   255
  43.       Left            =   240
  44.       TabIndex        =   3
  45.       Top             =   960
  46.       Width           =   975
  47.    End
  48.    Begin Label Label1 
  49.       BackStyle       =   0  'Transparent
  50.       Caption         =   "Text 1:"
  51.       Height          =   255
  52.       Left            =   240
  53.       TabIndex        =   1
  54.       Top             =   480
  55.       Width           =   1095
  56.    End
  57.    Begin Menu mnuOptionsPopup 
  58.       Caption         =   "&Options"
  59.       Begin Menu mnuOption 
  60.          Caption         =   "&Always on Top"
  61.          Index           =   0
  62.       End
  63.    End
  64. End
  65. Option Explicit
  66.  
  67. Const IDM_TOPMOST = 0
  68.  
  69. ' NUMEXECUTECMDS is the number of execution commands MINUS 1.
  70. Const NUMEXECUTECMDS = 1
  71. Const EC_DISPLAYABOUT = 0
  72. Const EC_SHELLAPP = 1
  73. Dim ExecuteCmd(NUMEXECUTECMDS) As String
  74.  
  75. Function Cmd_ShellApp (Params As String)
  76.  Dim rtn As Integer
  77.  Dim sRtn As String
  78.  Dim appname As String
  79.  Dim state As Integer
  80.  
  81.    ' Shell the application defined by Params
  82.    ' First, extract the application name
  83.    If DoExtractParam(Params, appname) Then
  84.       ' Next extract the show state, if specified
  85.       state = 1
  86.       If DoExtractParam(Params, sRtn) Then
  87.          state = Val(sRtn)
  88.       End If
  89.       ' Now, shell the application
  90.       Cmd_ShellApp = Shell(appname, state)
  91.       Exit Function
  92.    Else
  93.       ' No app name found
  94.       Cmd_ShellApp = False
  95.       Exit Function
  96.    End If
  97. End Function
  98.  
  99. Sub DisplayStatus (sParam As String)
  100.    lblStatus.Caption = sParam
  101. End Sub
  102.  
  103. Function DoExtractParam (Params As String, sRtn As String)
  104.  Dim pStart, pEnd As Integer
  105.  Dim rtn As Integer
  106.  
  107.    DoExtractParam = True
  108.  
  109.    ' Extract next parameter
  110.    If Len(Params) = 0 Then
  111.       DoExtractParam = False
  112.       Exit Function
  113.    End If
  114.  
  115.    ' First, extract the next parameter and update the
  116.    ' Params string.
  117.    rtn = InStr(1, Params, ",") ' look next for commas
  118.    If rtn > 0 Then
  119.       ' More parameters follow. Extract the first into
  120.       ' 'sRtn' and update the Params string
  121.       sRtn = LTrim$(RTrim$(Left$(Params, rtn - 1)))
  122.       Params = Right$(Params, Len(Params) - rtn - 1)
  123.    Else
  124.       ' No parameters follow.
  125.       sRtn = LTrim$(RTrim$(Params))
  126.       Params = ""
  127.    End If
  128.    ' Clean up sRtn. Eliminate any leading or trailing
  129.    ' parenthesis and blanks
  130.    If Left$(sRtn, 1) = Chr$(34) Then
  131.       sRtn = LTrim$(Right$(sRtn, Len(sRtn) - 1))
  132.    End If
  133.    If Right$(sRtn, 1) = Chr$(34) Then
  134.       sRtn = RTrim$(Left$(sRtn, Len(sRtn) - 1))
  135.    End If
  136. End Function
  137.  
  138. Function DoLinkExecute (CmdStr As String)
  139.  Dim CommandStr As String
  140.  Dim CmdNumber As Integer
  141.  Dim Params As String
  142.  Dim rtn As Integer
  143.  
  144.    ' Provide for simple execution commands.
  145.    ' Return TRUE if successful, FALSE otherwise.
  146.  
  147.    ' Make local copy of command string
  148.    CommandStr = CmdStr
  149.    rtn = ParseCommand(CommandStr, CmdNumber, Params)
  150.    Do While rtn <> -1
  151.       Select Case CmdNumber
  152.       Case EC_DISPLAYABOUT
  153.          MsgBox "Display About..." + Params
  154.       Case EC_SHELLAPP
  155.          If Cmd_ShellApp(Params) = 0 Then GoTo ExecuteError
  156.       Case Else
  157.       End Select
  158.       If rtn = 0 Then
  159.          DoLinkExecute = False
  160.          Exit Function
  161.       End If
  162.       rtn = ParseCommand(CommandStr, CmdNumber, Params)
  163.    Loop
  164. ExecuteError:
  165.    ' Error has occurred. Return TRUE.
  166.    DoLinkExecute = True
  167. End Function
  168.  
  169. Sub Form_LinkClose ()
  170.    DisplayStatus "Link Closed"
  171. End Sub
  172.  
  173. Sub Form_LinkError (LinkErr As Integer)
  174.    DisplayStatus "Link Error : " + Str$(LinkErr)
  175. End Sub
  176.  
  177. Sub Form_LinkExecute (CmdStr As String, Cancel As Integer)
  178.    DisplayStatus "Link Execute Attempted"
  179.    Cancel = DoLinkExecute(CmdStr)
  180. End Sub
  181.  
  182. Sub Form_LinkOpen (Cancel As Integer)
  183.    DisplayStatus "Link Opened"
  184. End Sub
  185.  
  186. Sub Form_Load ()
  187.    LoadExecuteCmds
  188. End Sub
  189.  
  190. Sub Form_Resize ()
  191.    lblStatus.Move 0, ScaleHeight - 255, ScaleWidth, 255
  192. End Sub
  193.  
  194. Sub LoadExecuteCmds ()
  195.    ' Load Execution commands into array. To add new
  196.    ' commands, be certain to update the NUMEXECUTECMDS
  197.    ' constant in the forms general declarations section.
  198.  
  199.    ExecuteCmd(EC_DISPLAYABOUT) = "DisplayAbout"
  200.    ExecuteCmd(EC_SHELLAPP) = "ShellApp"
  201. End Sub
  202.  
  203. Sub mnuOption_Click (Index As Integer)
  204.  
  205.    Select Case Index
  206.    Case IDM_TOPMOST
  207.       If mnuOption(Index).Checked Then
  208.          SetWindowPos hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
  209.       Else
  210.          SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE
  211.       End If
  212.    End Select
  213.    
  214.    ' Toggle menu checkmark
  215.    mnuOption(Index).Checked = Not mnuOption(Index).Checked
  216. End Sub
  217.  
  218. Function ParseCommand (CmdStr As String, CmdNumber As Integer, Params As String)
  219.  Dim CmdStart, CmdEnd, NextCmd As Integer
  220.  Dim pStart, pEnd As Integer
  221.  Dim Cmd As String
  222.  Dim ii As Integer
  223.  
  224.    ' Parse LinkExecute command and return the command number
  225.    ' and the parameter string. Return 1 if a valid command
  226.    ' is found, -1 if an invalid command is found, else
  227.    ' return 0 if end of command string.
  228.  
  229.    ' Find first left square bracket. If CmdStart = 1, no bracket
  230.    ' was found and we can assume no more commands exist so
  231.    ' we return a 0.
  232.    CmdStart = InStr(CmdStr, "[") + 1
  233.    If CmdStart = 1 Then ParseCommand = 0: Exit Function
  234.  
  235.    ' If CmdEnd is -1, no following left parenthesis was found.
  236.    ' Hence, an error was found.
  237.    CmdEnd = InStr(CmdStart, CmdStr, "(") - 1
  238.    If CmdEnd = -1 Then ParseCommand = -1: Exit Function
  239.    Cmd = UCase$(LTrim$(RTrim$(Mid$(CmdStr, CmdStart, CmdEnd - CmdStart + 1))))
  240.    pStart = InStr(CmdStart, CmdStr, "(") + 1
  241.    pEnd = InStr(pStart, CmdStr, ")") - 1
  242.    NextCmd = InStr(pEnd, CmdStr, "[")
  243.    
  244.    ' Find Cmd in ExecuteCmd array
  245.    For ii = 0 To NUMEXECUTECMDS
  246.       If UCase$(ExecuteCmd(ii)) = Cmd Then
  247.          ' Return the command number and parameters
  248.          Params = Mid$(CmdStr, pStart, pEnd - pStart + 1)
  249.          CmdNumber = ii
  250.  
  251.          If NextCmd = 0 Then
  252.             ' No following command; return 0
  253.             ParseCommand = 0
  254.          Else
  255.             ' Additional commands follow. Remove this
  256.             ' command from CmdStr and return 1.
  257.             CmdStr = Right$(CmdStr, Len(CmdStr) - NextCmd + 1)
  258.  
  259.             ' Set the return value
  260.             ParseCommand = 1
  261.          End If
  262.          Exit Function
  263.       End If
  264.    Next ii
  265.    ParseCommand = -1
  266. End Function
  267.  
  268. Sub Text1_Change ()
  269.    DisplayStatus ""
  270. End Sub
  271.  
  272. Sub Text2_Change ()
  273.    DisplayStatus ""
  274. End Sub
  275.  
  276.